﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Scroll
{
    class ScrollScene
    {
        private Texture2D tela1, tela2;
        private Vector2 posicaoXY;
        private Point posicaoSave;
        private float velocidade;
        private String[] fases;
        private Game1 game;
        private int indice;

        public ScrollScene(Texture2D tela1, Texture2D tela2, Point posicaoSave, Game1 game)
        {
            this.tela1 = tela1;
            this.tela2 = tela2;
            this.posicaoSave = posicaoSave;
            this.game = game;
            Initialize();
            
        }

        public void Initialize()
        {
            velocidade = 0.05f;
            indice = 0;
            fases = new String[4] {"imagem01","imagem02","imagem02","imagem01"}; //?
        }

        public void Update(GameTime gameTime)
        {
            if (posicaoXY.Y > tela2.Bounds.Height)
            {
                tela1 = tela2;
                tela2 = game.Content.Load<Texture2D>(fases[indice++]);

                if (indice > fases.Length - 1)
                {
                    indice = 0;
                }

                posicaoXY.Y = 0;
            }

            posicaoXY.Y += (float)gameTime.ElapsedGameTime.TotalMilliseconds * velocidade;


            //if (posicaoXY.X > tela2.Bounds.Width)
            //{
            //    tela1 = tela2;
            //    tela1 = game.Content.Load<Texture2D>(fases[indice++]);

            //    if (indice > fases.Length - 1)
            //    {
            //        indice = 0;
            //    }

            //    posicaoXY.X = 0;
            //}

            //posicaoXY.X += (float)gameTime.ElapsedGameTime.TotalMilliseconds * velocidade;
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(tela1, posicaoXY,
                new Rectangle(0, 0, tela1.Width, tela1.Height), Color.White,
                0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);

            spriteBatch.Draw(tela2, posicaoXY - new Vector2(posicaoSave.X, posicaoSave.Y),
                new Rectangle(0, 0, tela2.Bounds.Width, tela1.Bounds.Height), Color.White,
                0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f);
        }
    }
}
